var MyValidator = function() {
    var handleSubmit = function() {
        $('#tab').validate({
            errorElement : 'span',
            errorClass : 'help-block',
            focusInvalid : false,
            ignore : [],
            messages: {
				required: "字段不能为空"
			},

            highlight : function(element) {
                $(element).closest('.form-group').addClass('has-error');
            },

            success : function(label) {
                label.closest('.form-group').removeClass('has-error');
                label.remove();
            },

            errorPlacement : function(error, element) {
                var parent = element.parent();
                if (!parent.hasClass("controls")) {parent = parent.parent();};
                parent.append(error);
            },

            // submitHandler : function(form) {
            //     form.submit();
            // }
        });

        $('#tab input').keypress(function(e) {
            if (e.which == 13) {
                if ($('#tab').validate().form()) {
                    $('#tab').submit();
                }
                return false;
            }
        });
    }
    return {
        init : function() {
            handleSubmit();
        }
    };

}();